﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SXT.Utility;
using SXT.Party.PartyAdmin.BLL;
using System.Text;

namespace SXT.Party.PartyAdmin.Module.WorkTrends
{
    public partial class WorkTrendsList : ListPageBase
    {
        #region 属性
        /// <summary>
        /// 
        /// </summary>
        public string PageType
        {
            get
            {
                return Microsoft.Security.Application.AntiXss.HtmlEncode(Request.QueryString["PageType"] ?? "");
            }
        }

        /// <summary>
        /// 页面标识
        /// </summary>
        public override string PageSign
        {
            get
            {
                if (!string.IsNullOrEmpty(this.PageType))
                    return "BranchTrends";
                else
                    return "WorkTrends";
            }
        }
        #endregion

        #region Page_Load
        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            SXT.Party.Utility.PageUtility.CheckLogin(this);
            if (!this.Page.IsPostBack)
            {
                this.lbPagePath.Text = this.PagePath;
                this.BindData();
                this.LoadData();
            }
        }
        #endregion

        #region 数据访问
        /// <summary>
        /// BindData
        /// </summary>
        protected override void BindData()
        {
            if (string.IsNullOrEmpty(this.PageType))
                this.editDialog.Height = 410;
            this.btnAdd.DialogPageUrl = "WorkTrendsEdit.aspx?PageType=" + this.PageType;
            this.hfPageType.Value = this.PageType;
            this.hfBranchID.Value = this.BranchID;
            this.ppBranch.Value = this.BranchID;
            this.ppBranch.Text = SXT.Party.Utility.PartyOrg.QueryBranchName(this.ppBranch.Value);
            this.ppBranch.Enabled = this.CheckRight("Branch");

            SXT.Utility.Business.ControlBinding(this.ddlThematic, SXT.Party.PartyAdmin.Model.PartyThematicManage.GetGridData("", "True"), "Title", "ID", false);
            this.ddlThematic.Items.Insert(0, new ListItem() { Text = "普通活动", Value = "88888" });
            this.ddlThematic.Items.Insert(0, new ListItem() { Text = "===未选择===", Value = "99999" });
            this.ddlThematic.SelectedValue = "99999";
        }

        /// <summary>
        /// LoadData
        /// </summary>
        protected override void LoadData()
        {
            //绑定列表
            this.dgNotice.DataBind();
        }

        /// <summary>
        /// DeleteData
        /// </summary>
        protected override void DeleteData()
        {
            if (!string.IsNullOrEmpty(this.dgNotice.CheckedValue))
            {
                new Model.WorkTrends().BatchDelete(this.PageID, this.dgNotice.GridViewOptionalSetting.CheckValueField, this.dgNotice.CheckedList);
            }
        }
        #endregion

        #region 按钮事件
        /// <summary>
        /// 查询按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.LoadData();
        }

        /// <summary>
        /// 删除按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            this.DeleteData();
            this.LoadData();
        }
        #endregion

        protected void dgNotice_CreateDataSource(object sender, DataBoundEventArgs e)
        {
            string ddlThematicValue = "";
            if (this.ddlThematic.SelectedValue != "99999")
            {
                ddlThematicValue = this.ddlThematic.SelectedValue;
            }


            dgNotice.DataSource = Model.WorkTrends.GetGridData(e.PageIndex + 1, e.PageSize, this.txtTitle.Text, this.ppBranch.Value, "", ddlStatus.SelectedValue, ddlThematicValue);
        }
    }
}